/*
 * This is a wrapper that gives a access to a collection but allows for freezing and unfreezing of the collection.
 */
package org.yagnus.langutils.freezable;

import java.util.Collection;
import java.util.Iterator;
import org.yagnus.interfaces.Freezable;
import org.yagnus.exceptions.DisallowedOperationException;

/**
 *
 * @author hc.busy
 */
public class FreezableCollection<T> extends FreezableBase implements Freezable, Collection<T> {

    final Collection<T> c;

    public FreezableCollection(Collection<T> c) {
        this.c = c;
    }

    public <T> T[] toArray(T[] a) {
        return c.toArray(a);
    }

    public Object[] toArray() {
        return c.toArray();
    }

    public int size() {
        return c.size();
    }

    public boolean retainAll(Collection<?> c) {
        return this.c.retainAll(c);
    }

    public boolean removeAll(Collection<?> c) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        return this.c.removeAll(c);
    }

    public boolean remove(Object o) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        return c.remove(o);
    }

    public Iterator<T> iterator() {
        return c.iterator();
    }

    public boolean isEmpty() {
        return c.isEmpty();
    }

    public int hashCode() {
        return c.hashCode();
    }

    public boolean equals(Object o) {
        return c.equals(o);
    }

    public boolean containsAll(Collection<?> c) {
        return this.c.containsAll(c);
    }

    public boolean contains(Object o) {
        return c.contains(o);
    }

    public void clear() {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        c.clear();
    }

    public boolean addAll(Collection<? extends T> c) {
        if (c.size() > 0 && frozen) {
            throw new DisallowedOperationException();
        }
        return this.c.addAll(c);
    }

    public boolean add(T e) {
        if (frozen) {
            throw new DisallowedOperationException();
        }
        return c.add(e);
    }

}
